package loader.servlet;

import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import loader.TimerLoader;

public class LoaderServlet extends HttpServlet {

	private static final long serialVersionUID = -3753078970161859067L;
	private TimerLoader loader;

	/**
	 * Constructor of the object.
	 */
	public LoaderServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		loader.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 * 
	 * @throws ServletException
	 *             if an error occurs
	 */
	public void init() throws ServletException {

		Properties prop = System.getProperties();
		prop.setProperty("http.proxyHost", "10.132.145.24");
		prop.setProperty("http.proxyPort", "808");

		String sdelay = this.getServletContext().getInitParameter("delay");
		String scities = this.getServletContext().getInitParameter("cities");
		final int delay = Integer.parseInt(sdelay);
		final String[] cities = scities.split(",");

		loader = new TimerLoader(cities);
		loader.load(delay);
	}
}
